package com.excellent.item.mapper;

import com.excellent.item.pojo.Brand;
import org.apache.ibatis.annotations.*;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author Xxacker
 */
public interface BrandMapper extends Mapper<Brand> {
    /**
     * 新增商品分类和品牌中间表数据【 # 的效率比 $ 的效率更高】
     * @param cid 商品分类 id
     * @param bid 品牌 id
     * @return
     */
    @Insert("INSERT INTO TB_CATEGORY_BRAND(category_id, brand_id) VALUES (#{cid},#{bid})")
    int insertBrandAndCategory(@Param("cid") Long cid, @Param("bid") Long bid);

    /** 查询品牌信息 */
    @Select("SELECT b.ID, b.NAME, b.IMAGE, b.LETTER FROM TB_BRAND b INNER JOIN TB_CATEGORY_BRAND cb ON b.ID = cb.BRAND_ID WHERE cb.CATEGORY_ID = #{cid}")
    List<Brand> selectBrandByCid(Long cid);

    /**修改品牌信息*/
    @Update("UPDATE TB_BRAND b SET b.name = #{name}, b.image = #{image}, b.letter = #{letter} WHERE b.id = #{id}")
    int updateByBrand(Brand brand);

    /** 删除中间表数据 */
    @Delete("delete from TB_CATEGORY_BRAND where BRAND_ID = #{brandId}")
    int deleteByBrandId( @Param("brandId") Long brandId);

}
